<template>
  <div class="demo-page">

    <Amap
      :center="[120.2, 30.2]"
      :zoom="13"
      :markers="markers"
      @map-loaded="handleMapLoaded"
      @heatmap-toggle="handleHeatmapToggle"
      style="width: 3840px; height: 2160px"
    />
  </div>
</template>

<script setup>
import { ref, computed, watch } from "vue";
import Amap from "@/components/NewMap/index2.vue";
import img1 from "@/assets/矢量智能对象@2x.png";
import img2 from "@/assets/矢量智能对象@2x (1).png";
import img3 from "@/assets/矢量智能对象@2x (2).png";
import img4 from "@/assets/矢量智能对象@2x (3).png";
import img5 from "@/assets/矢量智能对象 拷贝 6@2x.png";
// 控制标记点显示的变量
const showHangzhou = ref(true);
const showScenicSpots = ref(true);
const showAll = ref(true);
// 控制热力图显示的变量
const showHeatmap = ref(false);

// 切换热力图显示
const toggleHeatmap = () => {
  showHeatmap.value = !showHeatmap.value;
  // 触发YMap组件中的toggleHeatmap方法
  window.dispatchEvent(new CustomEvent('toggleHeatmap'))
};

// 所有标记点数据
const allMarkers = [
  //西湖文化广场
  {
    position: [120.157891, 30.166789],
    title: "明德路",
    useIconImage: true,
    type: 1,
    bgIconImage: img1,
    iconImage: img2,
    id:1,
  },
  {
    // 西湖
    position: [120.1749223, 30.208109],
    title: "轮渡",
    useIconImage: true,
    color: "#4CAF50",
    size: "40px",
    iconText: "湖",
    type: 2,
    bgIconImage: img1,
    iconImage: img4,
    id:2
  },
  
  {
    position: [120.190826, 30.194148],
    title: "中南乐游城",
    useIconImage: true,
    type: 1,
    bgIconImage: img1,
    iconImage: img2,
    id: 3
  },
  {
    position: [120.186623, 30.16643],
    title: "冠山路",
    useIconImage: true,
    type: 1,
    bgIconImage: img1,
    iconImage: img3,
    id: 4
  },
  {
    position: [120.23206569780487, 30.19564015447044],
    title: "滨兴路",
    useIconImage: true,
    type: 1,
    bgIconImage: img1,
    iconImage: img5,
    id: 5
  },
  {
    position: [120.17395005598006, 30.193254434973525],
    title: "滨盛路",
    useIconImage: true,
    type: 1,
    bgIconImage: img1,
    iconImage: img3,
    id: 6
  },
  {
    position: [120.14165120134945, 30.19174850902506],
    title: "六合公园",
    useIconImage: true,
    type: 1,
    bgIconImage: img1,
    iconImage: img3,
    id: 7
  },
];

// 计算属性：根据控制变量动态计算要显示的标记点
const markers = computed(() => {
  return allMarkers;
});



const handleMapLoaded = (mapInstance) => {
  console.log("地图加载完成", mapInstance);
};

const handleHeatmapToggle = (isVisible) => {
  console.log("热力图状态:", isVisible ? "开启" : "关闭");
};
</script>

<style scoped>
.demo-page {
  position: relative;
}

.control-panel {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.95);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border: 1px solid #e0e0e0;
  min-width: 250px;
}

.control-panel h3 {
  margin: 0 0 12px 0;
  color: #333;
  font-size: 16px;
  font-weight: 600;
}

.control-group {
  margin-bottom: 10px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-group label {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #666;
  cursor: pointer;
}

.control-group input[type="checkbox"] {
  margin-right: 8px;
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.heatmap-btn {
  width: 100%;
  padding: 8px 12px;
  background: #ff4444;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.heatmap-btn:hover {
  background: #cc3333;
}
</style>
